//
//  MineViewController.m
//  MeterMart
//
//  Created by ENERGY on 2018/9/16.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "MineViewController.h"
#import "MineTableViewCell.h"
#import "LocationManageViewController.h"
#import "JoinTeamViewController.h"
#import "AboutUsViewController.h"
#import "WeChatLoginViewController.h"
#import "PhoneRegisterViewController.h"
#import "TeamViewController.h"
#import "MessageInformationViewController.h"
#import "CommonViewController.h"
#import "SuggestViewController.h"
#import "NormalCommunalController.h"
#import "WithdrawViewController.h"
#import "ChangeInfoViewController.h"
#import "MainViewController.h"
@interface MineViewController ()<UINavigationControllerDelegate, UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * headerView;
@property (nonatomic, strong)UIButton * headerImgBtn;//头像
@property (nonatomic, strong)UIButton * personInfoCoverBtn;//个人信息跳转按钮
@property (nonatomic, strong)UILabel * nameLab;//用户名
@property (nonatomic, strong)UIView * footerView;
@property (nonatomic, strong)UILabel * myExpendNum;//我的消费
@property (nonatomic, strong)UILabel * myCommissionNum;//我的账户
@property (nonatomic, strong)UILabel * withdrawMoneyNum;//可提现金
@property (nonatomic, strong)UILabel * refundNum;//我的退款
@property (nonatomic, strong)UILabel * unpayNum;//待付款
@property (nonatomic, strong)UILabel * payedNum;//已付款
@property (nonatomic, strong)UILabel * afterSaleNum;//退款/售后
@property (nonatomic, strong)UILabel * allListNum;//全部订单
@property (nonatomic, strong)NSString * payStatus;//订单状态
@property (nonatomic, strong)NSMutableArray * cellArr;
@property (nonatomic, strong)NSString * codeString;//微信登录回调code
@property (nonatomic, strong)NSString * ifPay;//1为没交会员钱，0为已交会员钱
@property (nonatomic, strong)NSString * serverPhoneNum;//客服电话
@property (nonatomic, strong)UIButton * otherBtn;//发展团队
@property (nonatomic, strong)NSDictionary * model;
@property (nonatomic, strong)NSString * phoneString;
@property (nonatomic, strong)NSString * tokenString;
@property (nonatomic, strong)UIButton * quitBtn;//退出账户
- (void)ifLogin;
@end
@implementation MineViewController(networking)
//我的信息
- (void)myInformationData{
    NSDictionary * dic = @{
                           @"phone":self.phoneString,
                           @"token":self.tokenString
                           };
    [self showprogressHUD];
    [[AFAppDotNetAPIClient sharedClient] POST:@"usiosApi/index" parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
        if ([responseObject[@"sign"] isEqualToString:@"1"]) {
            self.model = responseObject[@"list"];
        }else if ([[NSString stringWithFormat:@"%@", responseObject[@"sign"]] isEqualToString:@"400"]) {
            [self ifLogin];
        }else{
            self.model = nil;
            [self.quitBtn setTitle:@"登录" forState:UIControlStateNormal];
            [self.quitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            self.quitBtn.titleLabel.font = DEF_FontSize_14;
            [self.quitBtn setBackgroundColor:getColor(mainRedColor)];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
    }];
}
@end
@implementation MineViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.delegate = self;
    [self setStatusBarBackgroundColor:[UIColor clearColor]];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    if ([[UserModel sharedInstanced].token isEqualToString:@""] || [UserModel sharedInstanced].token == nil || [[UserModel sharedInstanced].token length] == 0 || [[UserModel sharedInstanced].mobile isEqualToString:@""] || [UserModel sharedInstanced].mobile == nil || [[UserModel sharedInstanced].mobile length] == 0) {
        self.tokenString = @"";
        self.phoneString = @"";
    }else{
        self.tokenString = [UserModel sharedInstanced].token;
        self.phoneString = [UserModel sharedInstanced].mobile;
    }
    [self myInformationData];//网络接口
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleDefault;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"";
    self.view.backgroundColor = [UIColor whiteColor];
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    [self.view addSubview:self.tableView];
}

#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    BOOL isHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isHomePage animated:YES];
}
#pragma mark - init
- (void)setModel:(NSDictionary *)model{
    _model = model;
    NSDictionary * dataDic = [NSDictionary dictionaryWithDictionary:model[@"us"]];
    self.serverPhoneNum = model[@"serverPhone"];//客服电话
    [self.headerImgBtn sd_setImageWithURL:[NSURL URLWithString:dataDic[@"headimg"]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"defaultHead"]];
    if ([dataDic[@"nickname"] isEqualToString:@""] || dataDic[@"nickname"] == nil || [dataDic[@"nickname"] length] == 0) {
        self.nameLab.text = @"用户名";
    }else{
        self.nameLab.text = dataDic[@"nickname"];
    }
    self.myExpendNum.text = dataDic[@"consumption"];//我的消费4
    self.myCommissionNum.text = dataDic[@"myaccount"];//我的佣金3
    self.withdrawMoneyNum.text = dataDic[@"presented"];//可提现金2
    self.refundNum.text = dataDic[@"refund"];//退款1
    NSDictionary * listData = [NSDictionary dictionaryWithDictionary:model[@"orderNumber"]];
    self.unpayNum.text = listData[@"unpaid"];//待付款
    self.payedNum.text = listData[@"alreadyPaid"];//已付款
    self.afterSaleNum.text = listData[@"refunded"];//退款/售后
    self.allListNum.text = listData[@"fullOrder"];//全部订单
    [self.quitBtn setTitle:@"退出账户" forState:UIControlStateNormal];
    self.quitBtn.titleLabel.font = DEF_FontSize_14;
    [self.quitBtn setTitleColor:getColor(textGrayColor) forState:UIControlStateNormal];
    [self.quitBtn setBackgroundColor:[UIColor whiteColor]];
}
- (NSMutableArray *)cellArr{
    if (!_cellArr) {
        _cellArr = @[
                     @{@"title":@"地址管理"},
                     @{@"title":@"常见问题"},
                     @{@"title":@"关于我们"},
                     @{@"title":@"意见反馈"}].mutableCopy;
    }return _cellArr;
}
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - TABBAR_HEIGHT) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = 58/WIDTH_6_SCALE;
        [_tableView registerClass:[MineTableViewCell class] forCellReuseIdentifier:NSStringFromClass([MineTableViewCell class])];
        _tableView.backgroundColor = getColor(mainColor);
        _tableView.tableHeaderView = self.headerView;
        _tableView.tableFooterView = self.footerView;
    }return _tableView;
}
- (UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] init];
        if (Is_Iphone_X) {
            _headerView.frame = CGRectMake(0, 0, 0, (485 - 117)/WIDTH_6_SCALE + 24);
        }else{
            _headerView.frame = CGRectMake(0, 0, 0, (485 - 117)/WIDTH_6_SCALE);
        }
        _headerView.backgroundColor = getColor(mainColor);
        [self setUpHeaderViews];//搭建头部控件
    }return _headerView;
}
- (UIView *)footerView{
    if (!_footerView) {
        _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 65/WIDTH_6_SCALE)];
        _footerView.backgroundColor = getColor(mainColor);
        //白色底
        self.quitBtn = [[UIButton alloc] initWithFrame:CGRectMake(15/WIDTH_6_SCALE, 10/WIDTH_6_SCALE, SCREEN_WIDTH - 30/WIDTH_6_SCALE, 44/WIDTH_6_SCALE)];
        [self.quitBtn addTarget:self action:@selector(quitBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.quitBtn setTitle:@"退出账户" forState:UIControlStateNormal];
        self.quitBtn.titleLabel.font = DEF_FontSize_14;
        [self.quitBtn setTitleColor:getColor(textGrayColor) forState:UIControlStateNormal];
        [self.quitBtn setBackgroundColor:[UIColor whiteColor]];
        [_footerView addSubview:self.quitBtn];
    }return _footerView;
}
- (void)setUpHeaderViews{
    //红色背景
    UIView * redBGView = [[UIView alloc] init];
    if (Is_Iphone_X) {
        redBGView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 170/WIDTH_6_SCALE + 24);
    }else{
        redBGView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 170/WIDTH_6_SCALE);
    }
    redBGView.backgroundColor = getColor(mainRedColor);
    [_headerView addSubview:redBGView];
    //白色背景
    for (int i = 0; i<2; i++) {
        UIView * whiteBGView = [[UIView alloc] init];
        if (Is_Iphone_X) {
            whiteBGView.frame = CGRectMake(15/WIDTH_6_SCALE, 134/WIDTH_6_SCALE + 117/WIDTH_6_SCALE * i + 24, SCREEN_WIDTH - 30/WIDTH_6_SCALE, 107/WIDTH_6_SCALE);
        }else{
            whiteBGView.frame = CGRectMake(15/WIDTH_6_SCALE, 134/WIDTH_6_SCALE + 117/WIDTH_6_SCALE * i, SCREEN_WIDTH - 30/WIDTH_6_SCALE, 107/WIDTH_6_SCALE);
        }
        whiteBGView.backgroundColor = [UIColor whiteColor];
        whiteBGView.tag = 1000 + i;
        [_headerView addSubview:whiteBGView];
    }
    //头像
    self.headerImgBtn = [[UIButton alloc] init];
    [self.headerImgBtn setImage:[UIImage imageNamed:@"defaultHead"] forState:UIControlStateNormal];
    self.headerImgBtn.layer.cornerRadius = (69/2)/WIDTH_6_SCALE;
    self.headerImgBtn.layer.masksToBounds = YES;
//    [self.headerImgBtn addTarget:self action:@selector(headerImgBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_headerView addSubview:self.headerImgBtn];
    //用户名
    self.nameLab = [[UILabel alloc] init];
    [self label:self.nameLab withFont:[UIFont systemFontOfSize:24.0] withText:@"" withTextColor:[UIColor whiteColor] withTextAlignment:NSTextAlignmentLeft withView:_headerView];
    //
    self.personInfoCoverBtn = [[UIButton alloc] init];
    [self button:self.personInfoCoverBtn withBGColor:[UIColor clearColor] withLayerBorderColor:nil withLayerBorderWith:0 withCornerRadius:0 withMasksToBounds:NO withViwe:_headerView];
    [self.personInfoCoverBtn addTarget:self action:@selector(headerImgBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    //客服
    UIImageView * serveImg = [[UIImageView alloc] init];
    serveImg.image = [UIImage imageNamed:@"serve"];
    [_headerView addSubview:serveImg];
    UIButton * serveCoverBtn = [[UIButton alloc] init];
    [serveCoverBtn setBackgroundColor:[UIColor clearColor]];
    [serveCoverBtn addTarget:self action:@selector(serveCoverBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_headerView addSubview:serveCoverBtn];
    //消息
    UIImageView * msgImg = [[UIImageView alloc] init];
    msgImg.image = [UIImage imageNamed:@"msg"];
    [_headerView addSubview:msgImg];
    UIButton * msgCoverBtn = [[UIButton alloc] init];
    [msgCoverBtn setBackgroundColor:[UIColor clearColor]];
    [msgCoverBtn addTarget:self action:@selector(msgCoverBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_headerView addSubview:msgCoverBtn];
    __weak typeof (self)weakSelf = self;
    //masonry
    int addHeight;
    if (Is_Iphone_X) {
        addHeight = 24;
    }else{
        addHeight = 0;
    }
    [self.headerImgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.headerView.mas_left).mas_offset(20/WIDTH_6_SCALE);
        make.top.equalTo(weakSelf.headerView.mas_top).mas_offset(54/WIDTH_6_SCALE + addHeight);
        make.width.height.mas_offset(69/WIDTH_6_SCALE);
    }];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.headerImgBtn.mas_right).mas_offset(11/WIDTH_6_SCALE);
        make.centerY.top.equalTo(weakSelf.headerImgBtn);
    }];
    [self.personInfoCoverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(weakSelf.headerImgBtn);
        make.right.equalTo(weakSelf.nameLab);
    }];
    [serveImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(17/WIDTH_6_SCALE);
        make.height.mas_offset(20.5/WIDTH_6_SCALE);
        make.top.equalTo(weakSelf.headerView.mas_top).mas_offset(30.5/WIDTH_6_SCALE + addHeight);
        make.right.equalTo(weakSelf.headerView.mas_right).mas_offset(-67/WIDTH_6_SCALE);
    }];
    [serveCoverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_offset(25/WIDTH_6_SCALE);
        make.centerX.equalTo(serveImg.mas_centerX);
        make.centerY.equalTo(serveImg.mas_centerY);
    }];
    [msgImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(17.5/WIDTH_6_SCALE);
        make.height.mas_offset(19.5/WIDTH_6_SCALE);
        make.centerY.equalTo(serveImg);
        make.right.equalTo(weakSelf.headerView.mas_right).mas_offset(-22/WIDTH_6_SCALE);
    }];
    [msgCoverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_offset(25/WIDTH_6_SCALE);
        make.centerX.equalTo(msgImg.mas_centerX);
        make.centerY.equalTo(msgImg.mas_centerY);
    }];
    [self whiteBGViewButtonViews];
}
- (void)whiteBGViewButtonViews{
    //我的消费、我的账户、可提金额、我的退款
    UIView * moneyView = (UIView *)[_headerView viewWithTag:1000];
    for (int i = 0; i<4; i++) {
        //图片
        UIImageView * iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 23/WIDTH_6_SCALE, 25/WIDTH_6_SCALE, 25/WIDTH_6_SCALE)];
        iconImg.tag = 10000 + i;
        [moneyView addSubview:iconImg];
        iconImg.centerX = moneyView.width/ 4 / 2 + (moneyView.width/ 4 * i);
        //金额
        UILabel * moneyLab = [[UILabel alloc] initWithFrame:CGRectMake(0, iconImg.bottom + 10/WIDTH_6_SCALE, moneyView.width/4, 13/WIDTH_6_SCALE)];
        moneyLab.centerX = iconImg.centerX;
        moneyLab.tag = 11000 + i;
        [self label:moneyLab withFont:DEF_FontSize_14 withText:@"---" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentCenter withView:moneyView];
        //标题
        UILabel * titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, moneyLab.bottom + 9/WIDTH_6_SCALE, moneyLab.width, 13/WIDTH_6_SCALE)];
        titleLab.centerX = moneyLab.centerX;
        titleLab.tag = 11100 + i;
        [self label:titleLab withFont:DEF_FontSize_12 withText:@"可提金额" withTextColor:getColor(@"a0a0a0") withTextAlignment:NSTextAlignmentCenter withView:moneyView];
        //覆盖按钮点击事件
        UIButton * moneyTypeBtn = [[UIButton alloc] initWithFrame:CGRectMake(moneyView.width/4 * i, 0, moneyView.width/4, moneyView.height)];
        [moneyTypeBtn setBackgroundColor:[UIColor clearColor]];
        moneyTypeBtn.tag = 11110 + i;
        [moneyView addSubview:moneyTypeBtn];
    }
    //金钱栏图标
    UIImageView * myExpendImg = (UIImageView *)[moneyView viewWithTag:10000];
    UIImageView * myCommissionImg = (UIImageView *)[moneyView viewWithTag:10001];
    UIImageView * withdrawMoneyImg = (UIImageView *)[moneyView viewWithTag:10002];
    UIImageView * refundImg = (UIImageView *)[moneyView viewWithTag:10003];
    myExpendImg.image = [UIImage imageNamed:@"myExpend"];
    myCommissionImg.image = [UIImage imageNamed:@"myCommission"];
    withdrawMoneyImg.image = [UIImage imageNamed:@"withdrawMoney"];
    refundImg.image = [UIImage imageNamed:@"refund"];
    //金钱栏标题
    UILabel * myExpendLab = (UILabel *)[moneyView viewWithTag:11100];
    UILabel * myCommissionLab = (UILabel *)[moneyView viewWithTag:11101];
    UILabel * withdrawMoneyLab = (UILabel *)[moneyView viewWithTag:11102];
    UILabel * refundLab = (UILabel *)[moneyView viewWithTag:11103];
    myExpendLab.text = @"我的消费";
    myCommissionLab.text = @"我的账户";
    withdrawMoneyLab.text = @"可提现金";
    refundLab.text = @"我的退款";
    //金钱栏各个钱数
    self.myExpendNum = (UILabel *)[moneyView viewWithTag:11000];
    self.myCommissionNum = (UILabel *)[moneyView viewWithTag:11001];
    self.withdrawMoneyNum = (UILabel *)[moneyView viewWithTag:11002];
    self.refundNum = (UILabel *)[moneyView viewWithTag:11003];
    self.myExpendNum.text = @"---";
    self.myCommissionNum.text = @"---";
    self.withdrawMoneyNum.text = @"---";
    self.refundNum.text = @"---";
    //金钱栏各个按钮点击
    UIButton * myExpendBtn = (UIButton *)[moneyView viewWithTag:11110];
    [myExpendBtn addTarget:self action:@selector(myExpendBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    UIButton * myCommissionBtn = (UIButton *)[moneyView viewWithTag:11111];
    [myCommissionBtn addTarget:self action:@selector(myCommissionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    UIButton * withdrawMoneyBtn = (UIButton *)[moneyView viewWithTag:11112];
    [withdrawMoneyBtn addTarget:self action:@selector(withdrawMoneyBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    UIButton * refundBtn = (UIButton *)[moneyView viewWithTag:11113];
    [refundBtn addTarget:self action:@selector(refundBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    //待付款、已付款、退款/售后、全部订单
    UIView * listView = (UIView *)[_headerView viewWithTag:1001];
    for (int i = 0; i<4; i++) {
        //图片
        UIImageView * iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 23/WIDTH_6_SCALE, 25/WIDTH_6_SCALE, 25/WIDTH_6_SCALE)];
        iconImg.tag = 20000 + i;
        [listView addSubview:iconImg];
        iconImg.centerX = moneyView.width/ 4 / 2 + (moneyView.width/ 4 * i);
        //数量
        UILabel * numLab = [[UILabel alloc] initWithFrame:CGRectMake(0, iconImg.bottom + 10/WIDTH_6_SCALE, moneyView.width/4, 13/WIDTH_6_SCALE)];
        numLab.centerX = iconImg.centerX;
        numLab.tag = 21000 + i;
        [self label:numLab withFont:DEF_FontSize_14 withText:@"-" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentCenter withView:listView];
        //标题
        UILabel * titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, numLab.bottom + 9/WIDTH_6_SCALE, numLab.width, 13/WIDTH_6_SCALE)];
        titleLab.centerX = numLab.centerX;
        titleLab.tag = 21100 + i;
        [self label:titleLab withFont:DEF_FontSize_12 withText:@"待付款" withTextColor:getColor(@"a0a0a0") withTextAlignment:NSTextAlignmentCenter withView:listView];
        //覆盖按钮点击事件
        UIButton * listTypeBtn = [[UIButton alloc] initWithFrame:CGRectMake(listView.width/4 * i, 0, listView.width/4, listView.height)];
        [listTypeBtn setBackgroundColor:[UIColor clearColor]];
        [listTypeBtn addTarget:self action:@selector(listTypeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        listTypeBtn.tag = 21110 + i;
        [listView addSubview:listTypeBtn];
    }
    //订单图标
    UIImageView * unpayImg = (UIImageView *)[listView viewWithTag:20000];
    UIImageView * payedImg = (UIImageView *)[listView viewWithTag:20001];
    UIImageView * afterSaleImg = (UIImageView *)[listView viewWithTag:20002];
    UIImageView * allListImg = (UIImageView *)[listView viewWithTag:20003];
    unpayImg.image = [UIImage imageNamed:@"unpay"];
    payedImg.image = [UIImage imageNamed:@"payed"];
    afterSaleImg.image = [UIImage imageNamed:@"afterSale"];
    allListImg.image = [UIImage imageNamed:@"orderList"];
    //订单标题
    UILabel * unpayLab = (UILabel *)[listView viewWithTag:21100];
    UILabel * payedLab = (UILabel *)[listView viewWithTag:21101];
    UILabel * afterSaleLab = (UILabel *)[listView viewWithTag:21102];
    UILabel * allListLab = (UILabel *)[listView viewWithTag:21103];
    unpayLab.text = @"待付款";
    payedLab.text = @"已付款";
    afterSaleLab.text = @"退款/售后";
    allListLab.text = @"全部订单";
    //订单具体数量
    self.unpayNum = (UILabel *)[listView viewWithTag:21000];
    self.payedNum = (UILabel *)[listView viewWithTag:21001];
    self.afterSaleNum = (UILabel *)[listView viewWithTag:21002];
    self.allListNum = (UILabel *)[listView viewWithTag:21003];
    self.unpayNum.text = @"-";
    self.payedNum.text = @"-";
    self.afterSaleNum.text = @"-";
    self.allListNum.text = @"-";
    //中间红线
    UIImageView * listLineImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, unpayImg.top + 8/WIDTH_6_SCALE, 5/WIDTH_6_SCALE, 41/WIDTH_6_SCALE)];
    listLineImg.centerX = self.afterSaleNum.right;
    listLineImg.image = [UIImage imageNamed:@"lineBorder"];
    [listView addSubview:listLineImg];
}
#pragma mark - action
- (void)ifLogin{
    [UserModel sharedInstanced].mobile = nil;
    [UserModel sharedInstanced].token = nil;
//    MainViewController *mainVc = [[MainViewController alloc] init];
//    [UIApplication sharedApplication].keyWindow.rootViewController =mainVc;
    WeChatLoginViewController * vc = [[WeChatLoginViewController alloc] init];
    UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc];
    vc.backHomePageBlock = ^{
        [vc dismissViewControllerAnimated:YES completion:nil];
        [self.tabBarController setSelectedIndex:0];
        [self.navigationController popToRootViewControllerAnimated:YES];
    };
    [self presentViewController:navi animated:YES completion:nil];
}
- (void)headerImgBtnClick:(UIButton *)sender{
    ChangeInfoViewController * vc = [[ChangeInfoViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    vc.headImg = self.headerImgBtn.imageView.image;
    vc.nameString = self.nameLab.text;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)serveCoverBtnClick:(UIButton *)sender{
    NSLog(@"客服");
    [self callPhone:self.serverPhoneNum];
}
- (void)msgCoverBtnClick:(UIButton *)sender{
    NSLog(@"消息");
    MessageInformationViewController * vc = [[MessageInformationViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)quitBtnClick:(UIButton *)sender{
//    if ([sender.titleLabel.text isEqualToString:@"退出账户"]) {
    [UserModel sharedInstanced].token = @"";
    [UserModel sharedInstanced].mobile = @"";
    [self.tabBarController setSelectedIndex:0];
//        MainViewController *mainVc = [[MainViewController alloc] init];
//        [UIApplication sharedApplication].keyWindow.rootViewController =mainVc;
//    }else{
//        WeChatLoginViewController * vc = [[WeChatLoginViewController alloc] init];
//        UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc];
//        [self.navigationController presentViewController:navi animated:YES completion:nil];
//    }
}

- (void)myExpendBtnClick:(UIButton *)sender{
    NSLog(@"我的消费");
}
- (void)myCommissionBtnClick:(UIButton *)sender{
    NSLog(@"我的账户");
}
- (void)withdrawMoneyBtnClick:(UIButton *)sender{
    NSLog(@"可提现金");
    WithdrawViewController * vc = [[WithdrawViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)refundBtnClick:(UIButton *)sender{
    NSLog(@"我的退款");
}
- (void)listTypeBtnClick:(UIButton *)sender{
    NSLog(@"tag：%ld",(long)sender.tag);
    if (sender.tag == 21110) {
        self.payStatus = @"0";
    }else if (sender.tag == 21111){
        self.payStatus = @"1";
    }else if (sender.tag == 21112){
        self.payStatus = @"2";
    }else if (sender.tag == 21113){
        self.payStatus = @"3";
    }
    [[NSNotificationCenter defaultCenter]postNotificationName:@"payStatus" object:nil userInfo:@{@"payStatus":self.payStatus}];
    [self.tabBarController setSelectedIndex:2];
}
- (void)payStatus:(NSNotification *)notification{
    NSDictionary * dic = notification.userInfo;
    NSLog(@"支付状态：%@", dic[@"payStatus"]);
}
#pragma mark - tableViewDelegate和tableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MineTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MineTableViewCell class]) forIndexPath:indexPath];
    cell.model = self.cellArr[indexPath.row];
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.cellArr.count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0){
        NSLog(@"地址管理");
        LocationManageViewController * vc = [[LocationManageViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 1){
        NormalCommunalController * vc = [[NormalCommunalController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        vc.navigationItem.title = @"常见问题";
        vc.pageType = @"1";
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 2){
        NSLog(@"关于我们");
        AboutUsViewController * vc = [[AboutUsViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        vc.navigationItem.title = @"关于我们";
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 3){
        NSLog(@"意见反馈");
        SuggestViewController * vc = [[SuggestViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 4){
        WeChatLoginViewController * vc = [[WeChatLoginViewController alloc] init];
        UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc];
        [self.navigationController presentViewController:navi animated:YES completion:nil];
    }
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"payStatus" object:nil];
}
@end
